package com.gome.util;

import java.io.IOException;
import java.net.InetSocketAddress;

import net.spy.memcached.MemcachedClient;

public class MemcacheManagerForSpy
// implements IMemcacheManager
{

	// 缓存客户端
	private MemcachedClient memcacheCient;
	// Manager管理对象，单例模式
	private static MemcacheManagerForSpy INSTANCE = new MemcacheManagerForSpy();

	private MemcacheManagerForSpy() {
		try {
			memcacheCient = new MemcachedClient(new InetSocketAddress("127.0.0.1", 11211));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static MemcacheManagerForSpy getInstance() {
		return INSTANCE;
	}

	// @Override
	public void add(String key, Object value, int milliseconds) {
		memcacheCient.add(key, milliseconds, value);
	}

	// @Override
	public void add(String key, Object value) {
		memcacheCient.add(key, 3600, value);

	}

	// @Override
	public void remove(String key, int milliseconds) {
		memcacheCient.delete(key);
	}

	// @Override
	public void remove(String key) {
		memcacheCient.delete(key);
	}

	// @Override
	public void update(String key, Object value, int milliseconds) {
		memcacheCient.replace(key, milliseconds, value);
	}

	// @Override
	public void update(String key, Object value) {
		memcacheCient.replace(key, 3600, value);
	}

	// @Override
	public Object get(String key) {
		return memcacheCient.get(key);
	}
	
	
	public static void main(String[] args) {
		MemcacheManagerForSpy ms = new MemcacheManagerForSpy();
	}
}
